package cn.tedu.straw.portal.util;

import lombok.Data;
import lombok.experimental.Accessors;

@Data
//chain=true 使用链式
@Accessors(chain=true)
public class R<T> {
  //  public static final Integer ERR_PARAM_VALIDATION =6 ;
    private Integer state;
    private String message;
    private T data;

    public static R ok(){
        return new R().setState(State.OK);
    }

    public static R failure(Integer status,String message){
        return new R().setState(status).setMessage(message);
    }

    public static R failure(Integer status,Throwable e){
        return new R().setState(status).setMessage(e.getMessage());
    }

    public static<E> R ok(E tags) {
        return new R().setState(State.OK).setData(tags);
    }

    public interface State{
        int OK=2000;
        int ERR_INVITE_CODE=4010;
        int ERR_CLASS_DISABLED=4020;
        int ERR_PHONE_DUPLICATE=4030;
        int ERR_INSERT=4040;
        int ERR_PARAM_VALIDATION=4050;
        int ERR_FILE_UPLOAD_SIZE =4160;
        int ERR_FILE_UPLOAD_STATE =4170;
        int ERR_FILE_UPLOAD_IO =4180;
        int ERR_FILE_UPLOAD_EMPTY =4190;
        int ERR_FILE_UPLOAD_TYPE =4100;
        int ERR_QUESTION_NOT_FOUND =4110;
        int ERR_ANSWER_NOT_FOUND =4120;

    }
}
